package com.wanxi.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MyFilterStream {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("张三");
        list.add("张三丰");
        list.add("张三李四");
        list.add("张冠李戴");
        list.add("李四");
        list.add("王五");

        Stream<String> stream = list.stream()
                .filter(s -> s.startsWith("张"))
                .filter(s -> s.length() == 3);
//        Stream<String> stream = list.stream().filter(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                return s.startsWith("张") && s.length() == 3;
//            }
//        });
        stream.forEach(s -> System.out.println(s));
//        stream.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });
//        System.out.println(stream.collect(Collectors.toList()));
    }
}
